package name.matthewgreet.example14.action; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ActionContext; import org.apache.struts2.ActionSupport; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import name.matthewgreet.example14.dto.PrimeMinisterDTO; import name.matthewgreet.example14.form.PrimeMinisterForm; import name.matthewgreet.example14.util.PrimeMinisterCompositeCache; import name.matthewgreet.example14.view.LocaleSelectBoxDisplay; import name.matthewgreet.example14.view.OtherCabinetPositionsSelectBoxDisplay; import name.matthewgreet.example14.view.PartySelectBoxDisplay; import name.matthewgreet.example14.view.PrimeMinisterDisplay; import name.matthewgreet.strutscommons.action.AbstractViewListActionSupport; import name.matthewgreet.strutscommons.util.ListCache; import name.matthewgreet.strutscommons.util.NA; /** * Displays page to edit a Prime Minister record where dates and date ranges are strings. */ @InterceptorRef("ViewStack") @Results({ @Result(name="list", type="redirectAction", params = {"namespace", "/", "actionName", "ViewPrimeMinisterList"}), @Result(name=ActionSupport.SUCCESS, location="/pages/PrimeMinister.jsp") }) public class ViewPrimeMinisterAction extends AbstractViewListActionSupport<NA,Integer,PrimeMinisterDTO,PrimeMinisterDisplay> { private static final long serialVersionUID = -7979376337555804889L; private Logger LOG = LogManager.getLogger(ViewPrimeMinisterAction.class); private PrimeMinisterForm form; private LocaleSelectBoxDisplay localeSelectBoxDisplay; private PartySelectBoxDisplay partySelectBoxDisplay; private OtherCabinetPositionsSelectBoxDisplay otherCabinetPositionsSelectBoxDisplay; @Override protected PrimeMinisterDisplay formatRecord(NA selectedMaster, PrimeMinisterDTO record) { return new PrimeMinisterDisplay(record); } @Override protected ListCache<NA, Integer, PrimeMinisterDTO> getListCache() { return PrimeMinisterCompositeCache.getInstance(getBrowserTabSession()).getMasterListCache(); } @Override protected ListCache<?, ?, NA> getMasterListCache() { return null; } @Override protected ViewListConfig getViewListConfig() { return ViewListConfig.makeSingleRecordConfig(); } protected String getViewResponse(NA selectedMaster, PrimeMinisterDTO selectedItem) throws Exception { localeSelectBoxDisplay = new LocaleSelectBoxDisplay(); localeSelectBoxDisplay.setSelectedValue(ActionContext.getContext().getLocale().getLanguage() + "_" + ActionContext.getContext().getLocale().getCountry()); if (form == null) { form = new PrimeMinisterForm(selectedItem); } partySelectBoxDisplay = new PartySelectBoxDisplay(); partySelectBoxDisplay.setSelectedValueWithConversionError(form.getParty(), "form.party"); otherCabinetPositionsSelectBoxDisplay = new OtherCabinetPositionsSelectBoxDisplay(); otherCabinetPositionsSelectBoxDisplay.setLocale(ActionContext.getContext().getLocale()); otherCabinetPositionsSelectBoxDisplay.setSelectedValuesWithConversionError(form.getOtherCabinetPositions(), "form.otherCabinetPositions"); return SUCCESS; } @Action("/ViewPrimeMinister") @Override public String execute() throws Exception { return super.execute(); } public PrimeMinisterForm getForm() { return form; } public LocaleSelectBoxDisplay getLocaleSelectBoxDisplay() { return localeSelectBoxDisplay; } @Override public Logger getLogger() { return LOG; } public OtherCabinetPositionsSelectBoxDisplay getOtherCabinetPositionsSelectBoxDisplay() { return otherCabinetPositionsSelectBoxDisplay; } public PartySelectBoxDisplay getPartySelectBoxDisplay() { return partySelectBoxDisplay; } }